/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Phan1.LietKe.QuayLui;

/**
 *
 * @author Giaotk
 */
public class TamHau {
    int n;
    int max = 100;
    int[] x = new int[max];
    boolean[] a = new boolean[max];
    boolean[] b = new boolean[2*max];
    boolean[] c = new boolean[2*max];
    StringBuilder result = new StringBuilder();
    
    public TamHau(int sohau){
        this.n = sohau;
        for (int i = 1; i <= 2*sohau; i++) {
            b[i]=true;
            c[i]=true;
        }
        for (int i = 1; i <= sohau; i++) {
            a[i] = true;
        }
        Attemp(1);
        
        System.out.println(result);
    }
    
    public void Attemp(int i){
        for (int j = 1; j <= n; j++) {
            if (a[j]&&b[i+j]&&c[n+i-j]) {
                x[i] = j;
                if (i==n) {
                    PrintResult();
                }else{
                    a[j] = b[i+j] = c[n+i-j] = false;
                    Attemp(i+1);
                    a[j] = b[i+j] = c[n+i-j] = true;
                }
            }
        }
    }
    
    public void PrintResult(){
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (j==x[i]) {
                    result.append(1);
                }else{
                    result.append("*");
                }
            }
            result.append("\n");
        }
        result.append("\n");
    }
}
